-
-
Notifications
You must be signed in to change notification settings - Fork 963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: refactor identity persister #3101
Conversation
0d3659e
to
54d4d28
Compare
Codecov Report
@@ Coverage Diff @@
## master #3101 +/- ##
==========================================
+ Coverage 77.50% 77.58% +0.08%
==========================================
Files 314 316 +2
Lines 19897 19908 +11
==========================================
+ Hits 15421 15446 +25
+ Misses 3285 3273 -12
+ Partials 1191 1189 -2
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
0a97994
to
a0fb6bd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking pretty good already! Note to myself: i need to review the identity persister changes
@@ -134,7 +132,6 @@ func TestPool(ctx context.Context, conf *config.Config, p interface { | |||
assert.Empty(t, actual.RecoveryAddresses) | |||
assert.Empty(t, actual.VerifiableAddresses) | |||
|
|||
require.Len(t, actual.InternalCredentials, 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reason for removal?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Software that imports kratos as a package might choose to hydrate the credentials in a different way, bypassing InternalCredentials
. This tests implementational details, which we shouldn't do IMO.
LMKWYT.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Persister reviewed :) Great stuff! Conceptually, this is shippable. Just a few comments :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Just one question concerning SQL injection.
ae2b1f9
to
9b15dcf
Compare
9b15dcf
to
cb16649
Compare
This reverts commit 0f187f6.
if err := c.Store.GetContext(ctx, &count, c.Dialect.TranslateSQL(stmt), v.GetID(), v.GetNID()); err != nil { | ||
return sqlcon.HandleError(err) | ||
} else if count == 0 { | ||
return errors.WithStack(sqlcon.ErrNoRows) | ||
} | ||
|
||
//#nosec G201 -- TableName is static | ||
stmt = fmt.Sprintf("UPDATE %s AS %s SET %s WHERE %s AND %s.nid = :nid", | ||
quoter.Quote(model.TableName()), | ||
model.Alias(), | ||
cols.Writeable().QuotedUpdateString(quoter), | ||
model.WhereNamedID(), | ||
model.Alias(), | ||
) | ||
|
||
if _, err := c.Store.NamedExecContext(ctx, stmt, v); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just saw this (it exists in the current code too) - NamedExecContext should return the number of rows affected, which we could use to return an error. But anyways this is an optimization for another day and another PR!
ctx, span := p.r.Tracer(ctx).Tracer().Start(ctx, "persistence.sql.FindByCredentialsIdentifier") | ||
defer span.End() | ||
otelx.End(span, &err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did the defer
go missing here? @alnr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, well spotted!
#3145
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you for double checking @jonas-jonas 🙏
ctx, span := p.r.Tracer(ctx).Tracer().Start(ctx, "persistence.sql.findIdentityCredentialsType") | ||
defer span.End() | ||
otelx.End(span, &err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here?
This is some groundwork to more easily plug different persisters into kratos.
I've shuffled some code around:
Other notes:
InternalCredentials
field is no longer routinely used to get credentials. Instead, we use an intelligent join to get the data in one go. Please review carefully.ref https://github.com/ory-corp/cloud/issues/4013